<template>
  <div>
<!--    <iframe v-for="(item,index) in iframeArr" :key="index" :src="aaa[index]"  style="position:absolute;" />-->
    <el-form ref="form" :model="form" class="demo-form-inline" label-width="100px" style="margin-top: 20px">
      <el-form-item label="原密码" prop="jobName">
        <el-input v-model="form.oldPassword" />
      </el-form-item>
      <el-form-item label="新密码" prop="jobCount">
        <el-input v-model="form.newPassword" />
      </el-form-item>
      <el-form-item label="确认密码" prop="jobCount">
        <el-input v-model="form.againPassword" />
      </el-form-item>
      <el-form-item style="text-align: center">
        <el-button @click="onCancel">取消</el-button>
        <el-button :loading="loading" type="primary" @click="onSubmit('form')">修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { loginUpdatePassword } from '@/api/user'
import baseSsoUrl from '@/api/baseSsoUrl.js'
export default {
  name: 'EntUpdatePassword',
  data() {
    return {
      iframeArr: {},
      loading: false,
      form: {
        id: '',
        oldPassword: '',
        newPassword: '',
        againPassword: ''
      }
      // rules: {
      //   jobName: [
      //     { required: true, message: '请输入岗位名称', trigger: 'blur' },
      //     { max: 30, message: '岗位名称不得超过30字', trigger: 'blur' }
      //   ]
      // }
    }
  },
  created() {
    const that = this
    that.form.id = this.$route.query.id
    that.iframeArr = baseSsoUrl.mofangIframe
  },
  methods: {
    onSubmit() {
      const that = this
      const sendData = { oldPassword: that.form.oldPassword, newPassword: that.form.newPassword, againPassword: that.form.againPassword }
      loginUpdatePassword(sendData).then(response => {
        if (response.code === 200) {
          that.iframeArr.forEach(item => {
            that.$message.success('修改成功')
            this.$router.push('/entUser')
          })
        }
        if (response.code === 301) {
          that.$message.error('两次密码不一致')
        }
        if (response.code === 302) {
          that.$message.error('新密码不能与旧密码一致')
        }
        if (response.code === 300) {
          that.$message.error('原密码错误')
        }
        this.loading = false
      })
    },
    onCancel() {
      this.$router.push({ name: 'entUser' })
    }
  }
}
</script>

<style scoped>

</style>
